<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="app">
      <functional-child></functional-child>
    </div>
    <script src="vue.js"></script>
    <script>
        const FunctionalChild = {
            functional:true,
            inject:['theme'],//注入theme变量
            render(createElement,context){
                const {injections:{theme}} = context;
                return createElement('div',
                {
                    style:{
                        color:theme==='dark'?'white':'black',
                        backgroundColor:theme==='dark'?'black':'white'
                    }
                },`当前的主题为${theme}`);
            }
        }
        var vm = new Vue({
            el:'#app',
            provide:{
                theme:'dark'
            },
            components:{
                'functional-child':FunctionalChild
            }
        });
    </script>
</body>
</html>